package com.andreamerla.petslife.model;

import com.google.android.gms.maps.model.LatLng;
import com.google.api.client.util.Key;

import java.io.Serializable;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: a.merla
 * Date: 19/07/13
 * Time: 11.45
 */
public class Place implements Serializable {
    /**
     * Documentation: https://developers.google.com/places/documentation/details
     */

    @Key
    public List<AddressComponent> address_components;
    @Key
    public String formatted_address;
    @Key
    public String formatted_phone_number;
    @Key
    public Geometry geometry;
    @Key
    public String icon;
    @Key
    public String id;
    @Key
    public String international_phone_number;
    @Key
    public String name;
    @Key
    public OpeningHours opening_hours;
    @Key
    public List<Photo> photos;
    @Key
    public int price_level; // 0-4 value
    @Key
    public float rating; // 0.0-5.0 value
    @Key
    public String reference;
    @Key
    public List<Review> reviews;
    @Key
    public List<String> types;
    @Key
    public String url; // Google Places URL
    @Key
    public int utc_offset;
    @Key
    public String vicinity;
    @Key
    public String website; // Place website

    @Override
    public String toString() {
        return name + " - " + id + " - " + reference;
    }

    public static class AddressComponent implements Serializable {
        @Key
        public String long_name;
        @Key
        public String short_name;
        @Key
        public List<String> types;
    }

    public static class Geometry implements Serializable {
        @Key
        public Location location;

        public static class Location implements Serializable {
            @Key
            public double lat;
            @Key
            public double lng;
        }
    }

    public static class OpeningHours implements Serializable {
        @Key
        public boolean open_now;
        @Key
        public List<Period> periods;

        public static class Period implements Serializable {
            @Key
            public DayTime open;
            @Key
            public DayTime close;

            public static class DayTime implements Serializable {
                @Key
                public int day; // 0-6 value
                @Key
                public String time; // "hhmm" format
            }
        }
    }

    public static class Photo implements Serializable {
        @Key
        public int height;
        @Key
        public int width;
        @Key
        public String photo_reference;
    }

    public static class Review implements Serializable {
        @Key
        public AspectRating aspects;
        @Key
        public String author_name;
        @Key
        public String author_url;
        @Key
        public String text;
        @Key
        public long time;

        public static class AspectRating implements Serializable {
            @Key
            public String type;
            @Key
            public int rating; // 0-3 value
        }
    }

    public LatLng getLatLng() {
        return new LatLng(geometry.location.lat, geometry.location.lng);
    }
}